package com.softeem.yqst_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softeem.yqst_server.entity.Music;
import com.softeem.yqst_server.mapper.MusicMapper;
import com.softeem.yqst_server.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 音乐服务实现类，具体实现了对音乐资源的增删改查操作。
 */
@Service
public class MusicServiceImpl extends ServiceImpl<MusicMapper, Music> implements MusicService {


    @Autowired
    private MusicMapper musicMapper;

    @Override
    public boolean save(Music music) {
        musicMapper.insert(music);
        return false;
    }

    @Override
    public List<Music> list() {
        return musicMapper.selectList(null);
    }

    @Override
    public void removeById(Integer id) {
        musicMapper.deleteById(id);
    }

    @Override
    public List<Music> searchMusicByName(String keyword) {
        QueryWrapper<Music> wrapper = new QueryWrapper<>();
        wrapper.like("name", keyword);
        return musicMapper.selectList(wrapper);
    }

    @Override
    public boolean updateById(Music music) {
        musicMapper.updateById(music);
        return false;
    }

    @Override
    public Music getById(Integer id) {
        return musicMapper.selectById(id);
    }
}